<?php
/**
 * Created by JetBrains PhpStorm.
 * User: JKen22078
 * Date: 7/26/13
 * Time: 11:22 PM
 * To change this template use File | Settings | File Templates.
 */
?>
<?php
switch ($stt):
  case 'set':
    //var_dump($menu);die();
    ?>
    <?php echo form_open_multipart('upload/setInfo'); ?>
    <!--upload file-->
    <!--<input type="text" name="id" size="20" value = />-->
    <!--//chọn phong - get data phong từ tbl_office-->
    <input type="text" name="nameCat" size="20" value=""/>
    <select name="idCat">
      <?php
      echo '<option value="1" >------root------</option>';
      if($menu != false){
        foreach($menu as $list_menu){
          echo '<option value="'.$list_menu['0']->idCat.'" >'.$list_menu['0']->nameCat.'</option>';
          //var_dump($list_menu['0']->nameCat);
          if(isset($list_menu['1'])){
            foreach($list_menu['1'] as $list_menu_sub){
              echo '<option value="'.$list_menu_sub->idCat.'" disabled>&nbsp;&nbsp; - '.$list_menu_sub->nameCat.'</option>';
            }
          }
        }
      }
      ?>
    </select>
    <!--chon loai tai lieu-->
    <div><input type="submit" value="Insert"/></div>
    <?php echo form_close(); ?>
    <?php break;
  case 'OK':
   break;
  case 'update':
    if($menu != false){
      foreach($menu as $list_menu){
        echo '<a class="fancybox fancybox.ajax"  href="'.site_url('upload/task/item/'.$list_menu['0']->idCat).'" >'.$list_menu['0']->nameCat.'</a>';
        if(!isset($list_menu['1'])){
          echo '&nbsp;|&nbsp;
            <a class="fancybox fancybox.ajax" href = '.site_url('upload/task/delete/'.$list_menu['0']->idCat).'>Delete</a>';
        }
        echo '<br/>';
        if(isset($list_menu['1'])){
          foreach($list_menu['1'] as $list_menu_sub){
            echo '<a href="'.site_url('upload/task/item/'.$list_menu_sub->idCat).'" >&nbsp;&nbsp; - '.$list_menu_sub->nameCat.'</a>&nbsp;|&nbsp;
            <a href = '.site_url('upload/task/delete/'.$list_menu_sub->idCat).'>Delete</a><br/>';
          }
        }
      }
    }
    break;
  case 'item':
    echo form_open_multipart('upload/updateCat');
    $items = $item['0'];
    //var_dump($item);
    foreach($menu as $list_menu){
      if($list_menu['0']->idCat == $items->idCat && isset($list_menu['1'])){
        $dis = 'disabled';
        break;
      }else{
        $dis = '';
      }
    }
    ?>
    <input type="hidden" name ="idCat" value ="<?php echo $items->idCat;?>">
    <input type="text" name ="updateName" value="<?php echo $items->nameCat; ?>">
    <?php
    echo '<select name="parent" >';
    echo '<option value="1" >------root------</option>';
    if($menu != false){
      foreach($menu as $list_menu){
        /*if($list_menu['0']->idCat == $items->idCat && isset($list_menu['1'])){
            $dis = 'disabled';
        }else{
          $dis = '';
        }*/
        if($list_menu['0']->idCat == $items->idCat){
          echo '<option value="'.$list_menu['0']->idCat.'" style="background: rgb(218, 224, 75);" disabled>'.$list_menu['0']->nameCat.'</option>';
        }else{
          echo '<option value="'.$list_menu['0']->idCat.'" '.$dis.'>'.$list_menu['0']->nameCat.'</option>';
        }

        //var_dump($list_menu['0']->nameCat);
        if(isset($list_menu['1'])){
          foreach($list_menu['1'] as $list_menu_sub){
            if($list_menu_sub->idCat == $items->idCat){
              echo '<option value="'.$list_menu_sub->idCat.'" style="background: rgb(218, 224, 75);" disabled>&nbsp;&nbsp; - '.$list_menu_sub->nameCat.'</option>';
            }else{
              echo '<option value="'.$list_menu_sub->idCat.'"  disabled>&nbsp;&nbsp; - '.$list_menu_sub->nameCat.'</option>';
            }

          }
        }
      }
    }
    ?>
    <?php
    echo '</select>';
    echo '<input type="submit" value="Update">';
    echo form_close();
    break;
  case 'delete':
    if($delete == true){
      echo 'Delete ok';
    }else{
      echo 'Error';
    }
    break;
endswitch;?>